package ExerciseOne;

public class ThreadSafe3Test {
	public static void main(String[] args) {
		Window3 w = new Window3();
		Thread t1 = new Thread(w);
		Thread t2 = new Thread(w);
		t1.setName("线程一");
		t2.setName("线程二");
		t1.start();
		t2.start();
	}

}

class Window3 implements Runnable
{
	private int ticket = 100;
	
	@Override
	public void run() {
		while(true)
		{
			show();
		}
	}
	
	private synchronized void show()
	{
		if(ticket>0)
		{
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName()+":"+ticket);
			ticket--;
		}
	}
}